package com.xbfinal.ggkt.exception;

import com.xbfinal.ggkt.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ResponseBody//返回json数据
    @ExceptionHandler(Exception.class)   //全局异常处理Exception.class
    public Result error(Exception e){
        log.info("当前异常信息\n",e);
        return Result.fail("全局异常处理");
    }


    @ResponseBody
    @ExceptionHandler(GgktException.class)  //自定义的异常处理方法
    public Result divError(GgktException e){
        log.info("当前异常信息\n",e.getMsg());

        return Result.fail("自定义的异常处理"+e.getMsg()).setCode(e.getCode());
    }
}
